<?php include 'header.php';?>
<?php include 'sidebar.php';?>
<?php
$id = $_REQUEST["pid"];
$firstName = $_REQUEST["pfirstName"];
$lastName = $_REQUEST["plastName"];
$department = $_REQUEST["department"];
$research = $_REQUEST["research"];

$conn = mysql_connect("localhost", "root", "643313") or die(mysql_error());
mysql_select_db("regist_sys");

$sql = "SELECT * FROM professor";
$flag = false;
if (($id == "")&&($firstName=="")&&($lastName=="")&&($department=="")&&($research=="")) {

} else {
	$sql .= " WHERE ";
	if ($id!="") {
		$sql .=  " id='$id' ";
		$flag = true;
	}
	if ($firstName2!="") {
		if ($flag == true) {
			$sql .= " AND firstname='$firstName' ";
		} else {
			$sql .= " firstname='$firstName' ";
		}
	}
	if ($lastName!="") {
		if ($flag == true) {
			$sql .= " AND lastname='$lastName' ";
		} else {
			$sql .= " lastname='$lastName' ";
		}
	}
	if ($department2!="") {
		if ($flag == true) {
			$sql .= " AND department='$department' ";
		} else {
			$sql .= " department='$department' ";
		}
	}
	if ($research!="") {
		if ($flag==true) {
			$sql .= " AND research='$research' ";
		} else {
			$sql .= " research='$research' ";
		}
	}
}
$result = mysql_query($sql, $conn) or die(mysql_error());

?>
<div id="main">
	<fieldset>
		<legend>Professor Search Result</legend>
		<table cellpadding="5px" border="1">
			<tr>
				<td>Professor ID</td>
				<td>First Name</td>
				<td>Last Name</td>
				<td>Department</td>
				<td>Research Area</td>
			</tr>
			<?php
			while ($row = mysql_fetch_assoc($result)) {
				echo "<tr>";
				echo "<td>";
				echo $row["id"];
				echo "</td>";
				echo "<td>";
				echo $row["firstname"];
				echo "</td>";
				echo "<td>";
				echo $row["lastname"];
				echo "</td>";
				echo "<td>";
				echo $row["department"];
				echo "</td>";
				echo "<td>";
				echo $row["research"];
				echo "</td>";
				echo "</tr>";
			}
			?>
		</table>
	</fieldset>

</div>
			<?php include 'footer.php';?>